package com.itmuch.common.cat;

import com.dianping.cat.servlet.CatFilter;
import com.itmuch.common.cat.feign.FeignCat;
import com.itmuch.common.cat.filter.HttpCatCrossFliter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * Created by zhengwenzhu on 2017/1/17.
 */

@Configuration
@Import({FeignCat.class})
public class CatFilterConfigure {
    private Logger logger = LoggerFactory.getLogger(CatFilterConfigure.class);

    @Bean
    public FilterRegistrationBean catFilter() {
        logger.info("----------------------catFilter start---------------");
        FilterRegistrationBean registration = new FilterRegistrationBean();
        CatFilter filter = new CatFilter();
        registration.setFilter(filter);
        registration.addUrlPatterns("/*");
        registration.setName("cat-filter");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean httpCatCrossFilter() {
        logger.info("----------------------httpCatCrossFilter start---------------");
        FilterRegistrationBean registration = new FilterRegistrationBean();
        HttpCatCrossFliter filter = new HttpCatCrossFliter();
        registration.setFilter(filter);
        registration.addUrlPatterns("/*");
        registration.setName("cat-httpCatCrossFilter");
        registration.setOrder(2);
        return registration;
    }
}
